# Contributor: Fernando Casas Schossow <casasfernando@outlook.com>
# Maintainer: Fernando Casas Schossow <casasfernando@outlook.com>
pkgname=ocaml-xml-light
_pkgname=xml-light
pkgver=2.5
pkgrel=0
pkgdesc="Minimal XML parser and printer for OCaml"
url="https://github.com/ncannasse/xml-light"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="dune ocaml"
subpackages="$pkgname-dev"
source="$_pkgname-$pkgver.tar.bz2::https://github.com/ncannasse/xml-light/releases/download/$pkgver/xml-light-$pkgver.tbz"
builddir="$srcdir/$_pkgname-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --build-dir=.testenv
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
fec6b83f8342a37bdad0fc745032f1faa57b359365ab53c2376fb031613a83a3139766f2d646a9b9b8d67da25252f2499a03de4caaef7bd8738f9b183ef84b6e  xml-light-2.5.tar.bz2
"
